package com.nxbw.service.impl;

import com.nxbw.mapper.AcceptanceMapper;
import com.nxbw.pojo.dto.AcceptanceQuery;
import com.nxbw.pojo.dto.AcceptanceSaveParam;
import com.nxbw.pojo.entity.Acceptance;
import com.nxbw.service.AcceptanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
@Transactional
public class AcceptanceServiceImpl implements AcceptanceService {



    @Autowired
    AcceptanceMapper acceptanceMapper;
    @Override
    public List<AcceptanceQuery> getValitionQueryList(AcceptanceQuery acceptanceQuery) {
        log.debug("查询业务入参: {}",acceptanceQuery);
        List<AcceptanceQuery> list = acceptanceMapper.getAcceptanceQueryList(acceptanceQuery);
        log.debug("查询业务结果出参: {}",list);
        System.out.println(list);
        return list;
    }

    @Override
    public void saveAcceptance(AcceptanceSaveParam acceptanceSaveParam) {
        log.debug("保存业务入参: {}",acceptanceSaveParam);
        Acceptance acceptance=new Acceptance();
        BeanUtils.copyProperties(acceptanceSaveParam,acceptance);
        if (acceptance.getId()==null){  //新增
            log.debug("新增业务入参: {}",acceptanceSaveParam);
            acceptance.setCreateTime(new Date());
            acceptance.setEnterDate(new Date());
            acceptanceMapper.saveAcceptance(acceptance);
            log.debug("新增业务结果出参: {}",acceptance);
        }else {   //修改，编辑
            log.debug("修改业务入参: {}",acceptanceSaveParam);
            acceptanceMapper.updateAcceptance(acceptance);
            log.debug("修改业务结果出参: {}",acceptance);
        }
    }

    @Override
    public void deleteAcceptance(Integer id) {
        log.debug("删除业务入参: {}",id);
        acceptanceMapper.deleteAcceptance(id);
        log.debug("删除业务结果出参: {}",id);
    }
}
